<include file="Common:header" />
<!-- /. NAV SIDE  -->
<include file="Common:left" />
<!-- /. NAV SIDE  -->
<script type="text/javascript" charset="utf-8" src="__UEDITOR__/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__UEDITOR__/ueditor.all.js"></script>
<script type="text/javascript" src="__UEDITOR__/lang/zh-cn/zh-cn.js"></script>
<style type="text/css">
	.layui-upload-img{
		width:100px;
		height:100px;
		margin: 0 10px 10px 0;
	}
	.layui-upload-img2{
		width:200px;
		margin: 0 10px 10px 0;
	}
	.layui-upload-img3{
		width:50px;
	}
   .layui-form-item .layui-form-label{
		float: left;
		display: block;
		padding: 9px 15px;
		width: 100px;
		font-weight: 400;
		line-height: 20px;
		text-align: right;
	}
</style>
<div id="page-wrapper">
	<div class="header">
		<h1 class="page-header">
			产品管理 <small>Welcome {$Think.config.system_tag}</small>
		</h1>
		<ol class="breadcrumb">
			<li><a href="{:U('Index/index')}">首页</a></li>
			<li><a href="{:U('Goods/cardList')}">会员卡列表</a></li>
			<li class="active">编辑会员卡</li>
			<div style="float:right"><a href="javascript:history.go(-1);">返回</a></div>
		</ol> 
	</div>
	<div id="page-inner">
		<div class="row">
			<div class="col-xs-12">
				<!--Search content-->
				<div class="panel panel-default">
					<div class="panel-body">
						<form class="layui-form" action="" id="postform">
						    <input type="hidden" name="id" id="goods_id" value="{$info.id}">
                            <input type="hidden" name="spec_type" id="spec_type" value="{$info.spec_type}">
                            <input type="hidden" name="is_more_spec" id="is_more_spec" value="{$info.is_more_spec}">
                            <input type="hidden" name="type" value="2">
							<div class="layui-form-item">
								<label class="layui-form-label" style="width:auto">图片(多图)</label>
								<div class="layui-input-block">
									<div class="layui-upload">
									  <button type="button" class="layui-btn" id="test1">上传图片</button>
									  <div class="layui-upload-list" id="demo1" data-id="">
									    <volist name="imgUrlList" id="vo" key="k">
											<div class="layui-inline">
												<input type="hidden" name="smallimage[]" id="smallimage" value="{$vo}">
												<img src="{$vo}" class="layui-upload-img">
												<div style="text-align:center"><a href="javascript:;" onclick="$(this).parent().parent().remove();">删除</a></div>
											</div>
										</volist>
									  </div>
									  <div id="demoText"></div>
									</div> 
								</div>
							</div>
							<div class="layui-form-item">
                        		<label class="layui-form-label">所属场馆</label>
                        		<div class="layui-input-block">
                        			<select name="store_id">
                        				<option value="">请选择</option>
                        				<notempty name="storeList">
                        					<volist name="storeList" id="vo" key="key">
                        						<option value="{$vo.id}" <if condition="$info['store_id'] eq $vo['id']">selected</if>>{$vo.title}</option>
                        					</volist>
                        				</notempty>
                        			</select>
                        		</div>
                        	</div>
							<div class="layui-form-item">
								<label class="layui-form-label">商品名</label>
								<div class="layui-input-block">
								  <input value="{$info.goods_title}" type="text" name="goods_title" required  lay-verify="required" placeholder="请输入商品名" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">分类</label>
								<div class="layui-input-block">
									<select name="cate_id" lay-verify="required">
										<option value="">请选择</option>
										<notempty name="goodsCateList">
											<volist name="goodsCateList" id="vo">
												<option value="{$vo.id}" <if condition="$info['cate_id'] eq $vo['id']">selected</if>>{$vo.cate_name}</option>
                                    <if condition="isset($vo['second_list'])">
                                       <assign name="secondList" value="$vo['second_list']" />
                                       <volist name="secondList" id="v">
                                           <option value="{$v.id}" <if condition="$info['cate_id'] eq $v['id']">selected</if>> &nbsp;&nbsp;—{$v.cate_name}</option>
                                       </volist>
                                    </if>
											</volist>
										</notempty>
									</select>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">卡次数</label>
								<div class="layui-input-block">
								  <input value="{$info.total_nums}" type="text" name="total_nums" placeholder="请输入卡次数" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">到期时间</label>
								<div class="layui-input-block">
    								<div class="layui-input-inline">
    								  <input value="{$info.valid_time}" type="text" name="valid_time" required  lay-verify="required" placeholder="请输入到期时间（天数）" autocomplete="off" class="layui-input">
    								</div>
    								<div class="layui-form-mid layui-word-aux">天</div>
    							</div>
							</div>
                            <!--商品规格选项-->
							<div id="fairy-is-attribute"></div>
							<!--商品类型选择-->
							<div id="fairy-product-type"></div>
							<!--商品属性表-->
							<div id="fairy-attribute-table"></div>
							<!--商品规格表-->
							<div id="fairy-spec-table"></div>
							<!--商品库存表-->
							<div id="fairy-sku-table"></div>

							<div class="layui-form-item layui-form-text">
								<label class="layui-form-label">内容</label>
								<div class="layui-input-block">
								  <script type="text/plain" id="myEditor" name="goods_content" style="width:100%;height:240px;">{$info.goods_content}</script>
								</div>
							</div>
                            <div class="layui-form-item">
								<label class="layui-form-label">是否新品</label>
								<div class="layui-input-block">
								  <input type="radio" name="is_new" value="0" title="否" <if condition="$info.is_new eq 0">checked</if>>
								  <input type="radio" name="is_new" value="1" title="是" <if condition="$info.is_new eq 1">checked</if>>
								</div>
							</div>
                            <div class="layui-form-item">
								<label class="layui-form-label">是否热卖</label>
								<div class="layui-input-block">
								  <input type="radio" name="is_hot" value="0" title="否" <if condition="$info.is_hot eq 0">checked</if>>
								  <input type="radio" name="is_hot" value="1" title="是" <if condition="$info.is_hot eq 1">checked</if>>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">排序</label>
								<div class="layui-input-block">
								  <input value="{$info.sort}" type="text" name="sort" placeholder="请输入数字，数字越大越前面" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-input-block">
								  <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
								  <button type="reset" class="layui-btn layui-btn-primary">重置</button>
								</div>
						  </div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<include file="Common:foot" />
   <script>
		layui.config({
			base: '__ROOT__/public/lay-module/', // 设定扩展的 layui 模块的所在目录，一般用于外部模块扩展
		}).use(['layer', 'form', 'skuTable',], function () {
        var layer = layui.layer,
            form = layui.form,
            skuTable = layui.skuTable;

        var skuTableObj = skuTable.render({
            isAttributeElemId: 'fairy-is-attribute',
            productTypeElemId: 'fairy-product-type',
            attributeTableElemId: 'fairy-attribute-table',
            specTableElemId: 'fairy-spec-table',
            skuTableElemId: 'fairy-sku-table',
            //商品规格模式 0单规格 1多规格
            mode: $("#is_more_spec").val(),
            //是否开启sku表行合并
            rowspan: true,
            //图片上传接口
            uploadUrl: "{:U('Common/uploadImage2')}",
            //获取商品类型接口
            productTypeUrl: "{:U('Goods/getGoodsSpecType')}",
            //获取商品类型下的规格和属性接口
            attrSpecUrl: "{:U('Goods/getGoodsSpecValue',array('goods_id'=>$info['id']))}",
            //创建规格接口
            specCreateUrl: "{:U('Goods/createGoodsSpec')}",
            //删除规格接口
            specDeleteUrl: "{:U('Goods/deleteGoodsSpec')}",
            //创建规格值接口
            specValueCreateUrl: "{:U('Goods/createGoodsSpecValue')}",
            //删除规格值接口
            specValueDeleteUrl: "{:U('Goods/deleteGoodsSpecValue')}",
            //单规格SKU表配置
            singleSkuTableConfig: {
                thead: [
                    {title: '销售价(元)', icon: 'layui-icon-cols'},
                    {title: '市场价(元)', icon: 'layui-icon-cols'},
                    {title: '成本价(元)', icon: 'layui-icon-cols'},
                    {title: '状态', icon: ''},
                ],
                tbody: [
                    {type: 'input', field: 'selling_price', value: '0', verify: 'required|number', reqtext: '销售价不能为空'},
                    {type: 'input', field: 'market_price', value: '0', verify: 'required|number', reqtext: '市场价不能为空'},
                    {type: 'input', field: 'retail_price', value: '0', verify: 'required|number', reqtext: '成本价不能为空'},
                    {type: 'select', field: 'status', option: [{key: '启用', value: '1'}, {key: '禁用', value: '0'}], verify: 'required', reqtext: '状态不能为空'},
                ]
            },
            //多规格SKU表配置
            multipleSkuTableConfig: {
                thead: [
                    {title: '图片', icon: ''},
                    {title: '销售价(元)', icon: 'layui-icon-cols'},
                    {title: '市场价(元)', icon: 'layui-icon-cols'},
                    {title: '成本价(元)', icon: 'layui-icon-cols'},
                    {title: '状态', icon: ''},
                ],
                tbody: [
                    {type: 'image', field: 'goods_img_url', value: '', verify: '', reqtext: ''},
                    {type: 'input', field: 'selling_price', value: '0', verify: 'required|number', reqtext: '销售价不能为空'},
                    {type: 'input', field: 'market_price', value: '0', verify: 'required|number', reqtext: '市场价不能为空'},
                    {type: 'input', field: 'retail_price', value: '0', verify: 'required|number', reqtext: '成本价不能为空'},
                    {
                        type: 'select',
                        field: 'status',
                        option: [{key: '启用', value: '1'}, {key: '禁用', value: '0'}],
                        verify: '',
                        reqtext: ''
                    },
                ]
            },
            // ========================================== 回显时相关配置参数 ========================================== //
            //商品id
            productId: $("#goods_id").val(),
            //商品规格类型id
            productTypeId: 1,
            //sku数据接口
            skuDataUrl: "{:U('Goods/getGoodsSkuData')}",
        });
    });
	</script>
	<script>
		//Demo
		var ue = UE.getEditor('myEditor', {
         zIndex: 1 //设置编辑框层级
      });
		var sort = 1;
		layui.use('upload', function(){
			var $ = layui.jquery
			,upload = layui.upload;
			var uploadInst = upload.render({
				elem: '#test1'
				,url: "{:U('Common/uploadImage')}"
				,size:'1048576'
				,multiple: true
				,number:8
				,method: 'POST'
				,before: function(obj){
					//预读本地文件示例，不支持ie8
					obj.preview(function(index, file, result){
						
					});
				}
				,done: function(res){
					//如果上传失败
					var loadindex = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
					//如果上传失败
					if(res.code==0){
						return layer.msg(res.value);
					}else{
						$('#demo1').append('<div class="layui-inline"><input type="hidden" name="smallimage[]" id="smallimage" value="'+res.value+'"><img src="'+ res.value +'" class="layui-upload-img"><div style="text-align:center"><a href="javascript:;" onclick="$(this).parent().parent().remove();">删除</a></div></div>'); //图片链接（base64）
					}
					layer.close(loadindex);
				}
				,error: function(){
					//演示失败状态，并实现重传
					var demoText = $('#demoText');
					demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
					demoText.find('.demo-reload').on('click', function(){
						uploadInst.upload();
					});
				}
			});
		});
		layui.use('upload', function(){
			var $ = layui.jquery
			,upload = layui.upload;
			var uploadInst = upload.render({
				elem: '#test2'
				,url: "{:U('Common/uploadImage')}"
				,size:'0'
				,exts:'jpeg|gif|png|jpg'
				,multiple: false
				,method: 'POST'
				,before: function(obj){
					//预读本地文件示例，不支持ie8
					obj.preview(function(index, file, result){
						$('#demo2').html('<div><input type="hidden" name="goods_bg_pic" id="smallimage1"><img src="'+result +'" class="layui-upload-img2"></div>'); //文件名
					});
				}
				,done: function(res){
					//如果上传失败
					if(res.code==0){
						return layer.msg(res.value);
					}else{
						$('#smallimage1').val(res.value);
					}
				}
				,error: function(){
					//演示失败状态，并实现重传
					var demoText = $('#demoText1');
					demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
					demoText.find('.demo-reload').on('click', function(){
						uploadInst.upload();
					});
				}
			});
		});
		layui.use('upload', function(){
			var $ = layui.jquery
			,upload = layui.upload;
			var uploadInst = upload.render({
				elem: '#test3'
				,url: "{:U('Common/uploadImage')}"
				,size:'0'
				,exts:'jpeg|gif|png|jpg'
				,multiple: false
				,method: 'POST'
				,before: function(obj){
					//预读本地文件示例，不支持ie8
					obj.preview(function(index, file, result){
						$('#demo3').html('<div><input type="hidden" name="goods_img_url[]" id="smallimage3"><img src="'+result +'" width="50"></div>'); //文件名
					});
				}
				,done: function(res){
					//如果上传失败
					if(res.code==0){
						return layer.msg(res.value);
					}else{
						$('#smallimage3').val(res.value);
					}
				}
				,error: function(){
					//演示失败状态，并实现重传
					var demoText = $('#demoText3');
					demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
					demoText.find('.demo-reload').on('click', function(){
						uploadInst.upload();
					});
				}
			});
		});
		layui.use('upload', function(){
			var $ = layui.jquery
			,upload = layui.upload;
			var uploadInst = upload.render({
				elem: '#test4'
				,url: "{:U('Common/uploadImage')}"
				,size:'0'
				,exts:'jpeg|gif|png|jpg'
				,multiple: false
				,method: 'POST'
				,before: function(obj){
					//预读本地文件示例，不支持ie8
					obj.preview(function(index, file, result){
						$('#demo4').html('<div><input type="hidden" name="goods_img_url[]" id="smallimage4"><img src="'+result +'" width="50"></div>'); //文件名
					});
				}
				,done: function(res){
					//如果上传失败
					if(res.code==0){
						return layer.msg(res.value);
					}else{
						$('#smallimage4').val(res.value);
					}
				}
				,error: function(){
					//演示失败状态，并实现重传
					var demoText = $('#demoText4');
					demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
					demoText.find('.demo-reload').on('click', function(){
						uploadInst.upload();
					});
				}
			});
		});
		layui.use('upload', function(){
			var $ = layui.jquery
			,upload = layui.upload;
			var uploadInst = upload.render({
				elem: '#test5'
				,url: "{:U('Common/uploadImage')}"
				,size:'0'
				,exts:'jpeg|gif|png|jpg'
				,multiple: false
				,method: 'POST'
				,before: function(obj){
					//预读本地文件示例，不支持ie8
					obj.preview(function(index, file, result){
						$('#demo5').html('<div><input type="hidden" name="goods_img_url[]" id="smallimage5"><img src="'+result +'" width="50"></div>'); //文件名
					});
				}
				,done: function(res){
					//如果上传失败
					if(res.code==0){
						return layer.msg(res.value);
					}else{
						$('#smallimage5').val(res.value);
					}
				}
				,error: function(){
					//演示失败状态，并实现重传
					var demoText = $('#demoText5');
					demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
					demoText.find('.demo-reload').on('click', function(){
						uploadInst.upload();
					});
				}
			});
		});
		layui.use('form', function(){
		  var form = layui.form;
		  //监听提交
		  form.on('submit(formDemo)', function(data){
				var cont = $('#postform').serialize();
				$.ajax({
					url:"{:U('Goods/editGoods')}",
					type:'post',
					dataType:'json',
					data:cont,
					success:function(data){
						if(data.code==0){
							layer.alert(data.message);
						}else{
							layer.alert(data.message, function(index){
								//do something
								//window.parent.location.reload();
								//var index = parent.layer.getFrameIndex(window.name); 
								//parent.layer.close(index);
								window.location.href="{:U('Goods/cardList')}";
							});
						}
					}
				});
				//layer.msg(JSON.stringify(data.field));
				return false;
		  });
		});
	</script>
</div>
<include file="Common:footer" />